package com.eesujie.xcs;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;

@Component
class MyBatisPlusGeneration {
    private static final String url = "jdbc:mysql://localhost:3306/XCS?serverTimezone=GMT%2B8";
    private static final String username = "root";
    private static final String password = "123456";
    private static final DataSourceConfig.Builder dataSourceConfig= new DataSourceConfig.Builder(
            url, username, password)
            .dbQuery(new MySqlQuery())
            .schema("mybatis-plus")
            .typeConvert(new MySqlTypeConvert())
            .keyWordsHandler(new MySqlKeyWordsHandler());

    private static final String packageName = "com.eesujie.xcs";

    public static void main(String[] args) {
        FastAutoGenerator.create(dataSourceConfig)
                .globalConfig(globalConfig ->
                    globalConfig.outputDir(".\\generation")
                    .disableOpenDir()
                    .author("eesujie")
                    .build()
                ).packageConfig(packageConfig ->
                        packageConfig.parent(packageName)
                        .entity("entity.po")
                        .build()
                ).strategyConfig(strategyConfig ->
                    strategyConfig.entityBuilder()
                    .formatFileName("%sPO")
                    .enableLombok()
                    .disableSerialVersionUID()
                    .build()
                    .controllerBuilder()
                    .enableRestStyle()
                    .build()
                    .serviceBuilder()
                    .formatServiceFileName("%sService")
                    .build()
                    .mapperBuilder()
                    .mapperAnnotation(Mapper.class)
                    .build()
                ).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
